﻿using System;
using System.Linq;
using System.Text;
using Demo.Framework.Datastructures;

namespace Demo.Framework.DataStructures
{
    public class Queue<T>
    {
        private LinkedList<T> _linkedList;

        public Queue()
        {
            _linkedList = null;
        }

        /// <summary>
        /// FIFO
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool Enqueue(T value)
        {
            try
            {
                if (_linkedList.IsEmpty())
                    _linkedList.Insert(0, value);
                var tail = _linkedList.GetTail();
                tail.Next = new Node<T>(value);
                return true;
            }
            catch (Exception)
            {                
                return false;
            }          
        }

        public bool Dequeue()
        {
            try
            {
                if (!_linkedList.IsEmpty())
                {
                    _linkedList.Remove(0);
                }
                return true;
            }
            catch (Exception)
            {                
                return false;
            }            
        }
    }
}
